<template>
  <router-view :key="key" />
  <van-tabbar v-model="active" placeholder active-color="#42bbaa" route>
    <van-tabbar-item to="/home" icon="wap-home-o">首页</van-tabbar-item>
    <van-tabbar-item to="/category" icon="apps-o">分类</van-tabbar-item>
    <van-tabbar-item to="/shopcart" icon="cart-o" :badge="store.state.cartCount"
      >购物车</van-tabbar-item
    >
    <van-tabbar-item to="/profile" icon="manager-o">我的</van-tabbar-item>
  </van-tabbar>
</template>
<script>
import { computed, onMounted, ref } from 'vue'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
export default {
  setup () {
    const active = ref(0)
    const store = useStore()
    const router = useRoute()
    const key = computed(() => {
      return router.name ? router.name + new Date() : router.name + new Date()
    })
    onMounted(() => {
      store.dispatch('storeAddcart')
    })
    return {
      active,
      key,
      store
    }
  }
}
</script>
<style lang="less">
@import './assets/css/base.css';
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
.van-tabbar {
  background-color: #eee !important;
  box-shadow: 0 -2px 2px #eee;
  .van-tabbar-item--active {
    background-color: #eee !important;
  }
}
</style>
